define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'template/review/index' + location.search,
                    add_url: 'template/review/add',
                    edit_url: 'template/review/edit',
                    del_url: 'template/review/del',
                    multi_url: 'template/review/multi',
                    import_url: 'template/review/import',
                    table: 'template_review',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), searchable: false},
                        {field: 'user_id', title: __('User_id'),searchList: Config.userNameList,formatter: Table.api.formatter.normal},
                        {field: 'group_id', title: __('Group_id'),searchList: Config.groupNameList,formatter: Table.api.formatter.normal},
                        {field: 'category_id', title: __('Category_id'),searchList: Config.categoryNameList,formatter: Table.api.formatter.normal},
                        {field: 'product_name', title: __('Product_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'thumbnail', title: __('Thumbnail'), searchable: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'price', title: __('Price'), searchable: false},
                        {
                            field: 'status',
                            title: __('Status'),
                            searchList: {'0': '待审', '1': '已通过', '2': '驳回'},
                            formatter: Table.api.formatter.status
                        },
                        {field: 'product_id', title: __('Product_id'), searchable: false,searchList: Config.productNameList,formatter: Table.api.formatter.normal},
                        {field: 'check_user', title: __('Check_user'), operate: 'LIKE', searchable: false},
                        {field: 'reason', title: __('Reason'), searchable: false, formatter: Table.api.formatter.content},
                        // {field: 'snapshot', title: __('Snapshot')},
                        // {field: 'node_detail', title: __('Node_detail')},
                        {field: 'checktime', title: __('Checktime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
           $('.faupload').hide();
            $('.fachoose').hide();
            Controller.api.bindevent();
            $('.btn-trash').hide();
        },
        edit: function () {
           $('.faupload').hide();
            $('.fachoose').hide();
            Controller.api.bindevent();
            $('.btn-trash').hide();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
